from django.contrib.auth.models import User
from django.db import models

# Create your models here.
from utils.modelsMixin import ModelsSetMixin
from work.models import Label


class Article(ModelsSetMixin):
    STATUS_CHOICE = (
        (0, '未发布'),
        (1, '发布'),
    )
    title = models.CharField('文章标题', max_length=100)
    digest = models.CharField('文章摘要', max_length=300)
    content = models.TextField('文章内容')
    page_view = models.IntegerField('浏览量', default=0)
    priority = models.IntegerField('优先级', default=0)
    status = models.IntegerField('状态', choices=STATUS_CHOICE, default=0)

    label = models.ForeignKey(Label, on_delete=models.CASCADE)
    user = models.ForeignKey(User, on_delete=models.CASCADE)

    class Meta:
        ordering = ['-priority', '-page_view', '-c_time']
        db_table = 'article'
        verbose_name = '文章'
        verbose_name_plural = verbose_name


class Comment(models.Model):
    content = models.TextField('评论内容')
    level = models.IntegerField('评论等级', default=1)  # 1评论文章 2回复评论
    parent_comment = models.IntegerField('评论的id', null=True, blank=True)
    reply_comment = models.IntegerField('回复的id', null=True, blank=True)  # 存放当前回复的对象的id
    create_time = models.DateTimeField('评论时间', auto_now_add=True)

    article = models.ForeignKey(Article, on_delete=models.CASCADE)
    user = models.ForeignKey(User, on_delete=models.CASCADE)

    class Meta:
        ordering = ['-create_time']
        db_table = 'comment'
        verbose_name = '评论'
        verbose_name_plural = verbose_name
